<template>
  <section>
    <el-tabs tab-position="left">
      <el-tab-pane label="活动条件">
        <act-prop :activity="activity"></act-prop>
      </el-tab-pane>
      <el-tab-pane label="活动内容">
        <act-action :activity="activity" :department="department"></act-action>
      </el-tab-pane>
      <el-tab-pane label="活动图片">
        <act-img :activity="activity"></act-img>
      </el-tab-pane>
    </el-tabs>
    <el-button @click="saveBtn(activity)" size="mini" type="success">保存</el-button>
  </section>
</template>

<script>
  import dateFormater from '@/common/date-formater'
  import {mapGetters, mapActions, mapMutations} from 'vuex'
  import Vue from 'vue'//后续添加属性，需要vue联动
  import errHandler from '@/assets/errHandler'
  import actProp from './actProp'
  import actImg from './actImg'
  import actAction from './actAction'
  export default {
    name: "index",
    components:{actProp,actImg,actAction},
    props:['activity','department'],
    created(){
      console.log('————————————————————————',this.activity)
    },
    methods: {
      ...mapActions({
        fetch: 'fetch'
      }),
      formatDate(date){
        return dateFormater.formatDatetime(date)
      },
      saveBtn(activity){
        let tmp={
          id:activity.id,
          start:this.formatDate(activity.start),
          end:this.formatDate(activity.end),
          propertiesData:JSON.stringify(activity.propertiesData),
          actionData:JSON.stringify(activity.actionData)
        }
        tmp.data=JSON.stringify(activity.data)
        this.updateActivity(tmp)
      },
      updateActivity(act){
        this.fetch({name:"updateActivity",data:{...act},method:'post'})
          .then(res=>{
            console.log(res)
            this.$emit('cancel')
          })
          .catch(err=>{
            console.log(err)
            errHandler.handle(this,err)
          })
      }
    }
  }
</script>

<style scoped>

</style>
